package com.geostar.constructionland.common.dao.impl;

import com.geostar.constructionland.common.dao.LogSptDao;
import com.geostar.constructionland.common.entity.logs.LogSpt;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yelll
 * @since 2020-6-17 19:00
 **/
@Component
public class LogSptDaoImpl implements LogSptDao {
    @Autowired
    MongoTemplate mongoTemplate;
    @Override
    public void saveLogSpt(LogSpt logSpt) {
        mongoTemplate.save(logSpt);
    }

    @Override
    public List<LogSpt> findAllLogSpt() {
        return mongoTemplate.findAll(LogSpt.class);
    }

    @Override
    public List<LogSpt> findLogSpt(LogSpt logSpt) {
        Query query = new Query();
        if(StringUtils.isNotBlank(logSpt.getFxbs())){
            query.addCriteria(Criteria.where("fxbs").is(logSpt.getFxbs()));
        }
        if(StringUtils.isNotBlank(logSpt.getFxlx())){
            query.addCriteria(Criteria.where("fxlx").is(logSpt.getFxlx()));
        }

        return mongoTemplate.find(query,LogSpt.class);
    }
}
